import csv
import joblib
import pandas
raw = open('./result4.csv', 'r')
article = open('./Data/Processed/article_sparse.pkl','rb')
artid = joblib.load(article)
pcode = joblib.load(article)
artid_bidict = joblib.load(article)
customer = open('./Data/Processed/customer_feat.pkl','rb')
customer_id = joblib.load(customer)
FN = joblib.load(customer)
Active = joblib.load(customer)
club_member_status = joblib.load(customer)
fashion_news_frequency = joblib.load(customer)
age = joblib.load(customer)
customer_cnt = joblib.load(customer)
customer_bidict = joblib.load(customer)
rawreader = csv.reader(raw)
process = open('./result3.csv','w')
prowriter = csv.writer(process)
header = ['customer_id','prediction']
prowriter.writerow(header)
while True:
    try:
        alist = next(rawreader)
    except Exception :
        break
    res = list(map(int, alist))
    res[0] = customer_bidict.inverse[res[0]]
    for i in range(1,13):
        if(res[i] == 0):
            res[i] = 1
        res[i] = artid_bidict.inverse[res[i]]
    res = list(map(str,res))
    for i in range(2,13):
        res[1] = res[1] + '\n' + res[i]
    prowriter.writerow(res[0:2])

